<html>
<head>
<meta charset="UTF-8">
<title>批次实例信息列表</title>
	<link id="easyuiTheme" href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css" />
	<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css" />
	<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
	<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
<style>
	div.pot{margin:0 auto;height:20px;width:20px;border-radius: 20px;border: 1px solid #8b8b8b;}
    .selected{background-color: #cde4fc;}
	.tba,.tba th,.tba td{text-align:center;border: 1px solid #bcc1c2;border-collapse:collapse;}
	.tba th{font-weight:normal;font-size:15px;background-color: #5173a0;color:white}
	.tba th,.tba td{height:30px;min-width:30px;overflow:hidden;white-space:nowrap;}
	.tba td{font-size:14px;}
	.tba{min-width:850px;margin: 0 auto;border:none;}
	.tbHr{border-bottom:none;float:left;width:100%;}
</style>
<script type="text/javascript">

	var nodeListAttributes={};
	var batchState="";

	$(function() {
		inite()
	});

	function inite() {
		var batchSerialNo = $.getUrlParam('batchSerialNo');
		var batchId = $.getUrlParam('batchId');
		$.restfulGet('../../api/bat/inst/batch/' + batchSerialNo,null,function(data){
			batchState=data.rows.batchState;
			document.getElementById("batchName").innerHTML = data.rows.batchName;
			document.getElementById("batchState").innerHTML = getNameByDic(data.rows.batchState);
			document.getElementById("startTime").innerHTML = data.rows.startTime;
			document.getElementById("endTime").innerHTML = data.rows.endTime;
		});

		$.ajax({
			type: "get",
			url: '../../api/bat/inst/task/tree/' + batchSerialNo + '/' + batchId,
			data: {
			},
			success: function(data) {
				$("#taskPhase tbody").append(createBatchNode(data[0].children).toString()) ;
			}
		});
		//任务执行信息tab页
		$("#dg").datagrid({
			singleSelect : true,
			collapsible : true,
			url : '../../api/bat/inst/tasks',
			queryParams : {
				batchSerialNo : batchSerialNo,
				batchId : batchId,
				startTimeNotNull : true
			},
			method : 'post',
			toolbar : "#tb",
			title : "",
			rownumbers : true,
			pagination : true,
			pageSize : "20"
		});

		//装载信息tab页
		$("#dg2").datagrid({
			singleSelect : true,
			collapsible : true,
			url : '../../api/plugin/load/results',
			queryParams : {
				batchId : batchId,
				startTimeNotNull : true
			},
			method : 'post',
			toolbar : "#tb2",
			title : "",
			rownumbers : true,
			pagination : true,
			pageSize : "20"
		});

		//批次监控日志tab页，当用户选中该tab才加载数据
		$('#tabs').tabs({
			onSelect:function(title){
				if("批次监控日志" == title){
					$('#panelLog').panel({
						href: '../../api/batch/logs/run/' + batchId,
						onLoad:function(){
						}
					});
				}
			}
		});
		//批次运行中执行刷新
		if(batchState=='3'){
			setTimeout("inite()",5000);
		}
	}


	function getNameByDic(enname) {
		for(var i in this.BAT_BATCH_STATE){
			if(this.BAT_BATCH_STATE[i].enname==enname){
				return this.BAT_BATCH_STATE[i].cnname;
			}
		}
	}

	function createBatchNode(phases) {
		$("#taskPhase tbody").empty();
		var html="";
		for(var i in phases){
			var phase=phases[i];
			for(var s=0;s<phase.children.length/7;s++){
				if(s==0){
					html+="<tr><td><div id='"+phase.id+"'>"+phase.text+"</div></td>";
				}else{
					html+="<tr><td></td>";
				}
				for(var j=0;j<7;j++){
					if(j<phase.children.length){
						var task=phase.children[j];
						html+="<td><div id='"+task.id+"'onclick='selectTask(this.id)' style='cursor: hand;padding: 5px;'><div class='pot' style='background-color: "+getColor(task.attributes.taskRunState)+"'></div><div>"+task.text+"</div></div></td>";
						nodeListAttributes[task.id]=task.attributes;
					}else{
						html+="<td></td>";
					}
				}
				html+="</tr>";
			}
		}
		return html;
	}

	function selectTask(tid) {
		$("#taskPhase div").removeClass("selected");
		$("#"+tid).addClass("selected");
	}

	function getColor(taskRunState) {
		var color = "";
		if (taskRunState == 7) {
			color = "red";
		} else if (taskRunState == 2) {
			color = "#40a0ff";
		} else if (taskRunState == 4 || taskRunState == 3) {
			color = "#FFDA44";
		} else if (taskRunState == 1) {
			color = "#c000ff";
		} else if (taskRunState == 6) {
			color = "#00cc00";
		} else if (taskRunState == 0) {
			color = "#ffffff";
		}
		return color;
	}

	function buttomDisable(taskInfo) {
		if (taskInfo.taskInterveneState == 0 && taskInfo.taskRunState < 6) {
			$("#taskHangUp").linkbutton("enable");
		} else {
			$("#taskHangUp").linkbutton("disable");
		}

		if (taskInfo.taskInterveneState == 2) {
			$("#taskHangDown").linkbutton("enable");
		} else {
			$("#taskHangDown").linkbutton("disable");
		}

		if (taskInfo.taskRunState != 6 && taskInfo.taskInterveneState != 1) {
			$("#taskSkip").linkbutton("enable");
		} else {
			$("#taskSkip").linkbutton("disable");
		}

		if (taskInfo.taskRunState == 7) {
			$("#taskAgainRun").linkbutton('enable');
		} else {
			$("#taskAgainRun").linkbutton('disable');
		}

		if ((taskInfo.taskRunState == 2 || taskInfo.taskRunState == 3 || taskInfo.taskRunState == 4)
				&& taskInfo.taskInterveneState != 3) {
			$("#taskExit").linkbutton('enable');
		} else {
			$("#taskExit").linkbutton('disable');
		}
	}

	function doView() {
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			JLEUtil.createModalWin('详情', 'BatInstTaskView.html?' + 'batchId='
					+ row.batchId + '&batchOrder=' + row.batchOrder
					+ '&taskId=' + row.taskId);
		} else {
			$.messager.alert('提示', '请选择一条记录！', 'info');
		}
	}
	/*查询日志信息*/
	function doPluginExecLogList() {
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			//打开新页面
			JLEUtil.createModalWin('日志信息','PluginExecLogList.html?' + 'batchSerialNo='
					+ row.batchSerialNo + '&taskId=' + row.taskId);
		} else {
			$.messager.alert('提示', '请选择一条记录！', 'info');
		}
	}

	//修改
	function doUpdateBatInstTask() {
		var node=$("#taskPhase div.selected")[0];
		if (node) {
			var taskInfo = nodeListAttributes[node.id];
			JLEUtil.createModalWin('修改', 'BatInstTaskUpdate.html?'
					+ '&batchSerialNo=' + taskInfo.batchSerialNo  + '&taskId='
					+ taskInfo.taskId);
		} else {
			$.messager.alert('提示', '请选择一条任务！', 'info');
		}
	}

	//挂起
	function doTaskHangUp() {
		var node=$("#taskPhase div.selected")[0];
		if (node) {
			$.messager.confirm('提示', '是否确认要挂起任务？', function(r) {
				if (r) {
					var taskInfo = nodeListAttributes[node.id];
					$.restfulPut('../../api/bat/inst/task/hangup', taskInfo,
						function(data) {
							if (data.code == 0) {
								$.messager.alert('提示', '挂起成功！', 'success');
							} else {
								$.messager.alert('提示', '挂起失败！', 'error');
							}
						})
				}
			});
		} else {
			$.messager.alert('提示', '请选择一条任务！', 'info');
		}
	}

	//解挂
	function doTaskHangDown() {
		var node=$("#taskPhase div.selected")[0];
		if (node) {
			$.messager.confirm('提示', '是否确认要解挂任务？', function(r) {
				if (r) {
					var taskInfo = nodeListAttributes[node.id];
					$.restfulPut('../../api/bat/inst/task/hangdown', taskInfo,
							function(data) {
								if (data.code == 0) {
									$.messager.alert('提示', '解挂成功！', 'success');
								} else {
									$.messager.alert('提示', '解挂失败！', 'error');
								}
							})
				}
			});
		} else {
			$.messager.alert('提示', '请选择一条任务！', 'info');
		}
	}

	//置过
	function doTaskSkip() {
		var node=$("#taskPhase div.selected")[0];
		if (node && node.attributes) {
			$.messager.confirm('提示', '是否确认要置过任务？', function(r) {
				if (r) {
					var taskInfo = nodeListAttributes[node.id];
					$.restfulPut('../../api/bat/inst/task/skip', taskInfo,
							function(data) {
								if (data.code == 0) {
									$.messager.alert('提示', '置过成功！', 'success');
								} else {
									$.messager.alert('提示', '置过失败！', 'error');
								}
							})
				}
			});
		} else {
			$.messager.alert('提示', '请选择一条任务！', 'info');
		}
	}
	//装载信息查看
	function doView1(){
		var row = $('#dg2').datagrid('getSelected');
		if (row) {
			JLEUtil.createModalWin('详情','PluginLoadResultView.html?' + 'batchSerialNo=' + row.batchSerialNo + '&tableName=' + row.tableName);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

</script>
</head>
<body class="easyui-layout" style="padding: 10px">
	<div data-options="region:'north'" style="height: 100%; width: 100%;">
		<div id="tabs" class="easyui-tabs" data-options="fit:true" style="width: 100%;" id="top">
			<div title="批次信息" style="margin-top: 1px">
				<div data-options="region:'north',split:true" style="width: 100%; height: 100%;">
					<div style="margin-bottom: 2px;width:100%;background-color: #ebecee">
							<a href="javascript:doUpdateBatInstTask()" id="updateBatInstTask"
							   class="easyui-linkbutton" iconCls="icon-ok" plain="true">修改</a>
							<a href="javascript:doTaskHangUp()" id="taskHangUp"
								class="easyui-linkbutton" iconCls="icon-ok" plain="true">挂起</a>
							<a href="javascript:doTaskHangDown()" id="taskHangDown"
								class="easyui-linkbutton" iconCls="icon-ok" plain="true">解挂</a>
							<a href="javascript:doTaskSkip()" id="taskSkip"
								class="easyui-linkbutton" iconCls="icon-ok" plain="true">置过</a>
							<a href="javascript:doTaskAgainRun()" id="taskAgainRun"
								class="easyui-linkbutton" iconCls="icon-ok" plain="true"
								style="display: none;">重跑</a>
							<a href="javascript:doTaskExit()" id="taskExit" class="easyui-linkbutton" iconCls="icon-ok"
																 plain="true" style="display: none;">退出</a>
							<span style="color: #40a0ff">蓝色:执行中 </span>
							<span style="color: #000000">| </span>
							<span style="color: #c000ff"> 紫色:待执行 </span>
							<span style="color: #000000"> | </span>
							<span style="color: #00cc00">绿色:执行成功 </span>
							<span style="color: #000000"> | </span>
							<span style="color: #FFDA44"> 橙色:警告 </span>
							<span style="color: #000000">| </span>
							<span style="color: red"> 红色:执行失败 </span>
						</div>
					<form style="margin-top:20px;">
							<table id="taskPhase" class="tba">
								<thead>
								<tr style="background-color: white">
									<th colspan='8' style="font-size:16px;text-align: left;border: none;background-color: white;color:#3c3c3c;">
										<div style="display: inline-block;margin-right: 15px;"><span>批次名称：</span><span id="batchName"></span></div>
										<div style="display: inline-block;margin-right: 15px;"><span>批次状态：</span><span id="batchState"></span></div>
										<div style="display: inline-block;margin-right: 15px;"><span>开始时间：</span><span id="startTime"></span></div>
										<div style="display: inline-block;margin-right: 15px;"><span>结束时间：</span><span id="endTime"></span></div>
										<hr class="tbHr">
									</th>
								</tr>
								<tr>
									<th>阶段名称</th>
									<th>任务名称</th>
									<th>任务名称</th>
									<th>任务名称</th>
									<th>任务名称</th>
									<th>任务名称</th>
									<th>任务名称</th>
									<th>任务名称</th>
								</tr>
								</thead>
								<tbody>
								</tbody>
							</table>
					</form>
				</div>
				</div>
				<div title="任务执行信息" style="margin-top: 1px">
					<div id="tb" style="padding: 1px">
						<div style="margin-bottom: 2px">
							<a href="javascript:doView()" class="easyui-linkbutton"
							   iconCls="icon-ok" plain="true">查看</a> <a
								href="javascript:doPluginExecLogList()" class="easyui-linkbutton"
								iconCls="icon-ok" plain="true">任务日志</a>
						</div>
					</div>
					<table id="dg" style="height: 100%;">
						<thead>
						<tr>
							<th data-options="field:'batchSerialNo',resizable:true">批次流水号</th>
							<th data-options="field:'taskId',resizable:true">任务编号</th>
							<th data-options="field:'taskName',resizable:true">任务名称</th>
							<th data-options="field:'taskRunState',resizable:true"
								formatter="formatter_BAT_TASK_RUN_STATE">任务执行状态</th>
							<th data-options="field:'taskInterveneState',resizable:true"
								formatter="formatter_BAT_TASK_INTERVENE_STATE">任务干预状态</th>
							<th data-options="field:'startTime',resizable:true">启动时间</th>
							<th data-options="field:'endTime',resizable:true">结束时间</th>
							<th data-options="field:'costTime',resizable:true">运行时长（秒）</th>
						</tr>
						</thead>
					</table>
				</div>
				<div title="数据装载信息">
					<div id="tb2" style="padding: 1px">
						<form id="searchForm">
							<table>
								<tr>
									<td>&nbsp;批次流水号：</td>
									<td><input name="batchSerialNo" id="batchSerialNo" /></td>
									<td>&nbsp;数据库表名：</td>
									<td><input name="tableName" id="tableName" /></td>
									<td><a class="easyui-linkbutton" href="javascript:void(0);"
										   onclick="JLEUtil.queryForm('searchForm','dg2','../../api/plugin/load/results');">查找</a></td>
									<td><a class="easyui-linkbutton" href="javascript:void(0);"
										   onclick="JLEUtil.clearForm('searchForm');">清空</a></td>
								</tr>
							</table>
						</form>
						<div style="margin-bottom: 2px">
							<a href="javascript:doView1()" class="easyui-linkbutton"
							   iconCls="icon-ok" plain="true">查看</a>
						</div>
					</div>
					<table id="dg2" style="height: 100%">
						<thead>
						<tr>
							<th data-options="field:'batchSerialNo',resizable:true">批次流水号</th>
							<th data-options="field:'batchDate',resizable:true">批次日期</th>
							<th data-options="field:'tableName',resizable:true">数据库表名</th>
							<th data-options="field:'tableCnname',resizable:true">表中文名称</th>
							<th data-options="field:'tableType',resizable:true">数据表类型</th>
							<th data-options="field:'upSysname',resizable:true">供数系统名称</th>
							<th data-options="field:'tableLoadMode',resizable:true"
								formatter="formatter_BAT_TABLE_LOAD_MODE">数据装载方式</th>
							<th data-options="field:'loadFromFile',resizable:true">文件路径</th>
							<th data-options="field:'fileSize',resizable:true">文件大小</th>
							<th data-options="field:'startTime',resizable:true">启动时间</th>
							<th data-options="field:'endTime',resizable:true">结束时间</th>
							<th data-options="field:'costTime',resizable:true">运行时长</th>
							<th data-options="field:'readRows',resizable:true">读入条数</th>
							<th data-options="field:'loadRows',resizable:true">装入条数</th>
							<th data-options="field:'rejectRows',resizable:true">拒绝条数</th>
							<th data-options="field:'remark',resizable:true">备注</th>
							<th data-options="field:'loadResult',resizable:true"
								formatter="formatter_BAT_EXEC_RESULT">导数结果</th>
							<th data-options="field:'batchId',resizable:true">批次标识</th>
						</tr>
						</thead>
					</table>
				</div>
				<div title="批次监控日志" style="margin-top: 1px">
					<div id="panelLog" class="easyui-panel" title="console" loadingMessage="努力加载中..." data-options="iconCls:'icon-save', fit:true">
						<!-- 日志信息后台加载 -->
					</div>
				</div>
			</div>
		</div>
</body>
</html>
